<!DOCTYPE html>
<html lang="en">
	<head>
	    <meta charset="UTF-8">
	    <meta name="renderer" content="webkit">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	    <title>建新街道移动办公 - E事通</title>
	    <link rel="stylesheet" href="/app/static/layui/css/layui.css">
	    <link rel="stylesheet" href="/app/static/styles/style.css">
	    <link rel="stylesheet" type="text/css" href="/app/static/styles/dtree.css"/>
	    <link rel="icon" href="image/code.png">
	    <script src="/app/static/scripts/jquery-1.9.1.js"></script>
	    <script type="text/javascript" src="/app/static/layui/layui.all.js"></script>
		<script type="text/javascript" src="/app/static/scripts/index.js"></script>
		<script src="/app/static/scripts/dtree.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body class="body">
		<input type="hidden" name="jsid" value="" />
		<div class="section">
			<div class="wrapper-md">
	       		<h1 class="fl" id="title">权限管理</h1>
	       		<div class="fr">
	       			<div class="def-btn-group">
	       				<button class="def-btn def-btn-primary" onclick="save()"><i class="gopng gopng_page"></i> 保存</button>
	       			</div>
	       		</div>
	        </div>

			<div class="section-content">
				<div class="dtree">
					<p>
						<a href="javascript:d.closeAll();">展开</a> 
						| 
						<a href="javascript:d.openAll();">折叠</a>
					</p>
					<div id="dtree_wrapper">
						
					</div>
				</div>
				
			</div>
		</div>

		<script type="text/javascript">
			var dataList = [{"id":"1","cdmc":"网格管理","checked":true,"children":[{"id":"2","cdmc":"社区列表","checked":true},{"id":"3","cdmc":"网格列表","checked":true},{"id":"4","cdmc":"社工管理","checked":true}]},{"id":"5","cdmc":"人口信息","checked":false,"children":[{"id":"6","cdmc":"人口列表","checked":false}]},{"id":"7","cdmc":"政策法规","checked":false,"children":[{"id":"8","cdmc":"分类管理","checked":false},{"id":"9","cdmc":"内容管理","checked":false}]},{"id":"10","cdmc":"业务指南","checked":false,"children":[{"id":"11","cdmc":"分类管理","checked":false},{"id":"12","cdmc":"内容管理","checked":false}]},{"id":"13","cdmc":"日新广记","checked":false,"children":[{"id":"14","cdmc":"日新广记列表","checked":false}]},{"id":"15","cdmc":"公益银行","checked":false,"children":[{"id":"16","cdmc":"积分列表","checked":false}]},{"id":"17","cdmc":"设置管理","checked":true,"children":[{"id":"18","cdmc":"角色管理","checked":true},{"id":"19","cdmc":"管理员列表","checked":false},{"id":"20","cdmc":"操作日志","checked":false}]}]
			var form = layui.form,
				layer = layui.layer,
				layedit = layui.layedit,
				laydate = layui.laydate;
				form.render();
				
			
			function getMenuList(){
				renderDtree(dataList)
//				$.ajax({
//					type:"post",
//					url:"",
//					async:true,
//					data:{
//						
//					},
//					success:function(res){
//						renderDtree(dataList)
//					},
//					error:function(err){
//						layer.msg('获取列表出错',{icon:5})
//					}
//				});
			}
				
				
				
				
			function renderDtree(dataList){
				d = new dTree('d');
				d.add(0,-1,'权限管理');
				for(var i =0;i<dataList.length;i++){
					var pid = dataList[i].id;
					d.add(pid,0,'authority', pid ,dataList[i].cdmc, dataList[i].checked);
					if(dataList[i].children&&dataList[i].children.length){
						for(var j=0;j<dataList[i].children.length;j++){
							var cItem = dataList[i].children[j];
							var cid = cItem.id;
							d.add(cid,pid,'authority', cid, cItem.cdmc,cItem.checked);
						
						}
						
					}
	
				}
				document.write(d);
				d.openAll();
			}
				
				
				
			getMenuList();	
			
			
			function save() {
				var count = 0;
				var obj = document.all.authority;
				var newArr=[];
				for(i = 0; i < obj.length; i++) {
					if(obj[i].checked) {
						newArr.push(obj[i].value);
						count++;
					}
				}
				newArr = String(newArr);
				if(!newArr.length){
					layer.msg('至少选择一个',{icon:5})
					return ;
				}
				$.ajax({
					type:"post",
					url:"",
					async:true,
					data:{
						newArr:newArr
					},
					success:function(res){
						//renderDtree(res)
						location.href="/ss"
					},
					error:function(err){
						layer.msg('保存出错',{icon:5})
					}
				});
			}
			
			
			
			
			
		</script>
	</body>
</html>